home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / hc2_x / tcprogud.sit / TC Prog Guide / card_11123.txt < prev    next >
Text File  |  1991-02-27  |  1KB  |  30 lines

  1. -- card: 11123 from stack: in
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 4755
  5. -- name: 
  6.  
  7.  
  8. -- part contents for background part 4
  9. ----- text -----
  10. To declare and allocate space for a Person-type object named 'ralph', we would write:
  11.  
  12.     Person *ralph;
  13.     ralph = new(Person);
  14.  
  15. The first line defines a variable named ralph which may contain the address of a Person object, and the second line dynamically allocates space for a Person object and places its address in the variable ralph.  Using machine addresses like this is very common in C, and is discussed later in this chapter.
  16.  
  17. A method is invoked by sending the appropriate MESSAGE to the object.  (This is identical to "calling a procedure" in a procedural language, but we will use the OOP terminology since this leads to a more natural understanding of the program.)  To set and print ralph's instance variables, we would send the messages:
  18.  
  19.     ralph->set();
  20.     ralph->print();
  21.  
  22.  
  23.  
  24. -- part contents for background part 7
  25. ----- text -----
  26. 15
  27.  
  28. -- part contents for background part 17
  29. ----- text -----
  30. p17